package com.etekcity.vesync.common.plus.core;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;
import com.etekcity.vesync.common.plus.R;
import com.etekcity.vesync.common.util.UIUtils;
import com.wang.avi.AVLoadingIndicatorView;

/**
 * may use {@link R.layout#ek_cp_layout_progress}
 * @author liaoheng
 * @version 2016-8-23 17:05
 */
public class CPProgressHelper {

    private AVLoadingIndicatorView mProgressBar;
    private View                   mLayout;

    public static CPProgressHelper with(@NonNull View view) {
        View layout = view.findViewById(R.id.ek_cp_progress_layout);
        return new CPProgressHelper(layout,
                (AVLoadingIndicatorView) UIUtils.findViewById(view, R.id.ek_cp_progress));
    }

    public static CPProgressHelper with(@NonNull Activity activity) {
        View layout = activity.findViewById(R.id.ek_cp_progress_layout);
        return new CPProgressHelper(layout,
                (AVLoadingIndicatorView) UIUtils.findViewById(activity, R.id.ek_cp_progress));
    }

    public CPProgressHelper(AVLoadingIndicatorView progressBar) {
        mProgressBar = progressBar;
    }

    private CPProgressHelper(View layout, AVLoadingIndicatorView progressBar) {
        mLayout = layout;
        mProgressBar = progressBar;
    }

    public AVLoadingIndicatorView getProgressBar() {
        return mProgressBar;
    }

    public void visible() {
        mProgressBar.show();
        if (mLayout != null) {
            UIUtils.viewVisible(mLayout);
        }
    }

    public void gone() {
        mProgressBar.hide();
        if (mLayout != null) {
            UIUtils.viewGone(mLayout);
        }
    }
}
